<!--
 * @Description: 批次组详情
 * @Author: liyujie
 * @Date: 2021/3/16
 * @Last Modified by: liyujie
 * @Last Modified time: 2021/3/16
-->
<template>
    <div class="wrapper">
        <div class="content-wrapper">
            <!-- header -->
            <div class="header">
                <div class="header-title">
                    查看批次
                </div>
            </div>
            <!-- /header -->
            <el-tabs
                v-model="filterData.status"
                @tab-click="getTableData(1)"
            >
                <el-tab-pane
                    label="全部"
                    name="all"
                />
                <el-tab-pane
                    label="进行中"
                    name="1"
                />
                <el-tab-pane
                    label="已完成"
                    name="2"
                />
                <el-tab-pane
                    label="未完成"
                    name="-1"
                />
            </el-tabs>
            <!-- table -->
            <el-table
                :data="tableData"
                :loading="tableLoading"
                height="100%"
                style="width: 100%;"
                ref="tempLateName"
                class="data-table"
            >
                <el-table-column
                    label="序号"
                    align="center"
                    width="80"
                    type="index"
                />
                <el-table-column
                    prop="company_name"
                    label="公司名称"
                    show-overflow-tooltip
                    align="left"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    prop="series_index"
                    label="批次"
                    show-overflow-tooltip
                    align="left"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    prop="series_title"
                    label="产品名称"
                    show-overflow-tooltip
                    align="left"
                    :formatter="emptyFormatter"
                    width="120"
                />
                <el-table-column
                    label="寝室性别"
                    show-overflow-tooltip
                    align="center"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        {{ scope.row.series_sex === 1 ? '男' : scope.row.series_sex === 2 ? '女' : '不限' }}
                    </template>
                </el-table-column>
                <el-table-column
                    label="最近提交时间"
                    show-overflow-tooltip
                    align="center"
                    width="200"
                >
                    <template slot-scope="scope">
                        {{ scope.row.video_submit_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                    </template>
                </el-table-column>
                <el-table-column
                    show-overflow-tooltip
                    align="center"
                    width="110"
                    :formatter="emptyFormatter"
                    :render-header="(h, title, content) => renderHeader(h, '有效数量/目标数量', '有效数量指的是运营审核通过的数量，目标数量指的是，运营创建批次的时候给用户定的目标数量。')"
                >
                    <template slot-scope="scope">
                        {{ scope.row.video_student_audit_pass_count }} / {{ scope.row.room_series_count }}
                    </template>

                </el-table-column>
                <el-table-column
                    prop="video_student_audit_wait_count"
                    show-overflow-tooltip
                    align="center"
                    :render-header="(h, title, content) => renderHeader(h, '待审核数', '用户上传视频且提交了审核，总后台未进行审核的数量')"
                />
                <el-table-column
                    prop="video_student_audit_fail_count"
                    show-overflow-tooltip
                    align="center"
                    :render-header="(h, title, content) => renderHeader(h, '未通过数', '用户提交审核，未通过的数量')"
                />
                <el-table-column
                    prop="video_student_audit_submit_count"
                    show-overflow-tooltip
                    align="center"
                    :render-header="(h, title, content) => renderHeader(h, '提交总数', '用户上传视频且提交审核的数量之和')"
                />
                <el-table-column
                    prop="video_score"
                    show-overflow-tooltip
                    align="center"
                    :render-header="(h, title, content) => renderHeader(h, '总分数', '审核通过的视频分数之和，且是所有人的总分之和')"
                />
                <el-table-column
                    label="任务状态"
                    width="120"
                    align="center"
                >
                    <template slot-scope="scope">
                        <div class="status-wrapper">
                            <div
                                :class="`status-dot ${scope.row.status === 1 ? 'warning' : scope.row.status === 2 ? 'success' : 'normal'}`"
                                v-if="scope.row.status === -1"
                            />
                            <div class="status-name">{{ scope.row.status | statusName }}</div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column
                    prop="op_admin_true_name"
                    label="操作人"
                    align="center"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    label="操作"
                    align="left"
                    fixed="right"
                >
                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            @click="handleRoute('studentVideoVerify',{
                                no: scope.row.series_no,
                                student_no: scope.row.student_no,
                                from_no: filterData.from_no,
                                mode: 'detail',
                                series_title: scope.row.series_title,
                                series_index: scope.row.series_index,
                                company_name: scope.row.company_name
                            })"
                        >
                            查看视频
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>

            <!-- /分页 -->
            <!--<div class="pagination-wrapper clearfix">
                <el-pagination
                    layout="total, prev, pager, next, jumper"
                    background
                    :current-page.sync="page.now_page"
                    :total="page.total_count"
                    :page-size="page.page_size"
                    @current-change="getTableData"
                />
            </div>-->
            <!-- /table -->
        </div>
    </div>
</template>

<script>
import { back } from '@/mixin/back';
import { deepClone } from "@/assets/js/utils";

export default {
    name: 'SeriesGroupDetail',
    components: {},
    mixins: [back],
    filters: {
        statusName(val) {
            switch (val) {
                case 0:
                    return '全部';
                case 1:
                    return '进行中';
                case 2:
                    return '已完成';
                case -1:
                    return '未完成';
                default:
                    return '';
            }
        },
    },
    computed: {},
    data() {
        return {
            filterData: {
                status: 'all',
                student_no: '',
                series_no: '',
                from_type: 1,
                from_no: ''
            },
            tableData: [],
            tableLoading: false,
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },
            authResult: {}
        };
    },
    watch: {},

    mounted() {
        this.$store.commit('SET_HEADER', [{title: "APP后台"}, {title: '工作'}, {title: '精英任务领取列表',path: '/student/elite-task-receive-list?active=dorm'},{title: '查看批次'}]);
        this.authResult = this.$route.meta.authResult;
        let query = this.$route.query;

        this.filterData.student_no = query.student_no;
        this.filterData.series_no = query.no;
        this.filterData.from_no = query.from_no;
        this.getTableData();
    },

    methods: {

        /**
         * @description 获取表优惠券列表数据
         * @param page
         */
        getTableData(page) {
            let params = deepClone(this.filterData);

            if (params.status === 'all') {
                params.status = 99;
            } else {
                params.status = Number(params.status);
            }
            params.page_id = page || this.page.now_page;
            this.$post('/student/room_series_student_appoint%5Cget_link_hire_list', params, resp => {
                if (resp.code === 1) {
                    this.tableData = resp.data.list;
                    // this.page = resp.data.page;
                } else {
                    this.$notify({
                        title: '提示',
                        message: resp.msg,
                        type: 'warning'
                    });
                }
            });
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        },

        /**
         * 完成 未完成
         * @param row
         * @param type
         */
        handleComplete(row, type) {
            if(!this.authResult.auth_complete) {
                this.$notify({
                    title: '提示',
                    message: '请联系管理员添加权限',
                    type: 'warning',
                    duration: 2000
                });
                return false;
            }

            let params = {
                series_no: row.series_no,
                student_no: row.student_no,
                complete:type
            };

            this.$post('/student/room_series_student_appoint%5Cset_complete', params, resp => {
                if (resp.code === 1) {
                    this.$notify({
                        title: '提示',
                        message: '操作成功',
                        type: 'success'
                    });
                    this.getTableData();
                } else {
                    this.$notify({
                        title: '提示',
                        message: resp.msg,
                        duration: 2000,
                        type: 'warning'
                    });
                }
            });
        },

        /**
         * 自定义表格标题hover提示
         */
        renderHeader(h,title, content){
            return h('span', {}, [
                h('span', {}, title),
                h('el-popover', { props: { placement: 'top-start', width: '200', trigger: 'hover', content: content }}, [
                    h('i', { slot: 'reference', class:'el-icon-question',style: 'color:#666'}, '')
                ])
            ]);
        },

        /**
         * 路由跳转
         * @param routeName
         * @param query
         */
        handleRoute(routeName, query) {
            this.$router.push({
                name: routeName,
                query
            });
        },

        /**
         * 委派批次
         */
        handleAppoint() {
            if(!this.authResult.auth_appoint) {
                this.$notify({
                    title: '提示',
                    message: '请联系管理员添加权限',
                    type: 'warning',
                    duration: 2000
                });
                return false;
            }

            this.handleRoute('dormTaskSeriesAppoint', {no: this.filterData.student_no, from_no: this.filterData.from_no});
        }
    },
};
</script>

<style lang="less" scoped>
.wrapper {
    width: 100%;

    .content-wrapper {
        display: flex;
        height: calc(100% - 24px);
        flex-direction: column;
        position: relative;
        margin: 12px;
        background: #fff;
        box-sizing: border-box;

        /*header*/

        .header {
            height: 68px;
            padding: 24px;
            box-sizing: border-box;
            box-shadow: 0px -1px 0px 0px #F0F2F5;
            display: flex;
            align-items: center;
            justify-content: space-between;
            color: #333333;
            font-size: 20px;
            .header-title {
                font-weight: 500;
            }
        }

        /*el-tabs*/

        /deep/ .el-tabs {
            margin-top: -12px;

            .el-tabs__nav-wrap {
                height: 54px;
                padding-left: 24px;

                .el-tabs__nav-scroll {
                    .el-tabs__nav {
                        height: 54px;
                        line-height: 54px;
                    }
                }
            }
        }

        /*table*/
        // 表格
        .data-table {
            ::-webkit-scrollbar {
                width: 6px;
                height: 6px;
            }
            .el-button {
                margin-left: 0;
                margin-right: 10px;
                .el-icon-arrow-down {
                    margin-left: 0;
                }
            }
        }
        .status-wrapper {
            display: flex;
            align-items: center;
            justify-content: center;

            .status-dot {
                width: 6px;
                height: 6px;
                border-radius: 50%;
                margin-right: 5px;

                &.success {
                    background: #4CD964;
                }

                &.danger {
                    background: #FF3030;
                }

                &.warning {
                    background: #FFA72D;
                }

                &.normal {
                    background: #1890FF;
                }
            }
        }

        /* 分页 */

        .pagination-wrapper {
            padding: 10px 32px;

            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
}
</style>

